<template>
	<view class="container">
		<view class="main">
			<view class="list flex flex-align flex-bt" @click="go_url()">
				<view class="left">头像</view>
				<view class="right flex flex-align ">
					<button class=" flex flex-align flex-end" open-type="chooseAvatar" @chooseavatar="getupload">
						<image :src="headerimg" mode=""></image>
						<tui-icon name="arrowright" :size="26" color="#999999"></tui-icon>
					</button>
				</view>
			</view>
			<view class="list flex flex-align flex-bt" @click="go_url('/pages/setting/xiugai?type=1&&name=昵称')">
				<view class="left">昵称</view>
				<view class="right flex flex-align ">
					<view class="grey">{{userInfo.nickname}}</view>
					<tui-icon name="arrowright" :size="26" color="#999999"></tui-icon>
				</view>
			</view>
			
			<view class="list flex flex-align flex-bt" @click="go_url('/pages/setting/xiugai?type=3&&name=个性签名')">
				<view class="left">个性签名</view>
				<view class="right flex flex-align ">
					<view class="grey">{{userInfo.signature?userInfo.signature:'去设置'}}</view>
					<tui-icon name="arrowright" :size="26" color="#999999"></tui-icon>
				</view>
			</view>
			<view class="list flex flex-align flex-bt" @click="go_url()">
				<view class="left">手机号</view>
				<view class="right flex flex-align ">
					<button class=" flex flex-align flex-end" open-type="getPhoneNumber" @getphonenumber="getPhone">
						<view class="grey">{{userInfo.mMobile}}</view>
						<tui-icon name="arrowright" :size="26" color="#999999"></tui-icon>
					</button>
					
				</view>
			</view>
		</view>
		<view class="main" style="margin-top: 30rpx;">
			<view class="list flex flex-align flex-bt" @click="go_url()">
				<view class="left">ID</view>
				<view class="right flex flex-align ">
					<view class="grey">{{userInfo.id}}</view>
					<tui-icon name="arrowright" :size="26" color="#999999"></tui-icon>
				</view>
			</view>
		</view>
		<tui-datetime ref="dateTime" :type="2" :startYear="1950" :endYear="2020" :cancelColor="cancelColor" :color="color"
		 :setDateTime="setDateTime" :unitTop="unitTop" :radius="radius" @confirm="change"></tui-datetime>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				name:'',
				id_card:'',
				bank_num:'',
				array:['招商银行','中国银行'],
				index:0,
				mobile:'',
				yzm:'',
				headerimg:'',
				name:'',
				userInfo:'',
				cancelColor: '#888',
				color: '#000',
				setDateTime: '',
				result: '',
				unitTop: false,
				radius: false
			}
		},
		onLoad() {
	
		},
		onShow() {
			let that = this
			that.getData()
		},
		methods: {
			show(){
				this.$refs.dateTime.show();
			},
			go_url(e){
				console.log(e)
				let that = this
				that.tui.href(e)
			},
			bindPickerChange(e){
				console.log(e)
				let that = this
				that.index = e.detail.value
			},
			getPhone(e){
				console.log(e)
			},
			getupload(e){
				console.log(e)
				let that = this
				that.tui.request("api.auth.center/set", "PUT",{headimg:e.target.avatarUrl} , false, true, true).then((res) => {
					that.tui.toast(res.info)
					if(res.code==1){
						setTimeout(()=>{
							 that.getData()
						},1500)
					}
					
				}).catch((res) => {})
			},
			getData() {
				let that = this
				that.tui.request("api.auth.center/get", "GET", {}, false, true, true).then((res) => {
					that.userInfo = res.data.info
					that.headerimg =res.data.info.headimg
					if(res.nickname=='')
					that.name = res.data.info.nickname
				}).catch((res) => {})
			},
			postData(){
				let that = this
				let data ={avatar:that.headerimg?that.headerimg:'https://firework.cyx.zzcyx1688.cn/web/static/user_heder.png'}
				console.log(data)
				that.tui.request("v1/user/users", "PUT",data , false, true, false).then((res) => {
					that.tui.toast('修改成功')
					setTimeout(()=>{
						 that.getData()
					},1500)
				}).catch((res) => {})
			},
			change: function(e) {
				console.log(e);
				let that = this
				that.result = e.result;
				let data ={birthday:that.result}
				console.log(data)
				that.tui.request("v1/user/users", "PUT",data , false, true, false).then((res) => {
					that.tui.toast('修改成功')
					setTimeout(()=>{
						 that.getData()
					},1500)
				}).catch((res) => {})
			}
		}
	}
</script>

<style lang="scss">
	page{background: #f5f5f5;padding-top: 30rpx;}
	.grey{color: #b3b3b3;}
	.main{padding: 0 40rpx;background: #fff;
		.list{border-bottom: 1px solid #eee;height: 120rpx;
			.left{width: 150rpx;}
			.uni-input{padding:0 6rpx;}
			.right{
				image{width: 80rpx;height: 80rpx;border-radius: 100%;}
				button{background: transparent;border: none;padding: 0;}
				button:after{border: none;}
			}
			.liquan{border-radius: 40rpx;border: 1px solid #333;padding: 0 20rpx;font-size: 24rpx;}
		}
		.list:last-child{border-bottom: none;}
	}
	
	.padding{padding: 34rpx 30rpx 34rpx 40rpx;}
</style>